package com.abl.core.mybatis.config;

import com.abl.core.common.util.ObjectKit;
import com.mybatisflex.core.FlexGlobalConfig;
import com.mybatisflex.core.keygen.KeyGeneratorFactory;
import com.mybatisflex.core.query.QueryColumnBehavior;
import com.mybatisflex.spring.boot.MyBatisFlexCustomizer;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@MapperScan({"com.abl.core.mybatis.mapper"})
public class MyBatisFlexConfig implements MyBatisFlexCustomizer {

    @Override
    public void customize(FlexGlobalConfig globalConfig) {
        //ID生成器
        KeyGeneratorFactory.register("SnowflakeKey", new KeyGenSnowflake());

        //自动判断空值
        QueryColumnBehavior.setIgnoreFunction(ObjectKit::isBlank);

        //如果传入的值是集合或数组，则使用 in 逻辑，否则使用 =（等于） 逻辑：
        QueryColumnBehavior.setSmartConvertInToEquals(true);

        //全局逻辑删除字段 del
        globalConfig.setLogicDeleteColumn("del");

        //脱敏规则
        //        MaskManager.registerMaskProcessor("removePassword", data -> null);

    }

}